//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef  long long ll;


//最大异或点（暴力） 

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5+10;
int nums[N];
int pa[N];

int main() {
	int n;
	cin >> n;
	long long  nums[n];
	long long  pa[n];


	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}


	for (int i = 0; i < n; i++) {
		cin >> pa[i];
	}

	long long res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (pa[i] != j && pa[j] != i) {
				res = max(res, nums[i] ^ nums[j]);
			}
		}
	}

	cout << res << endl;
	return 0;
}


//贪心 一定要审题仔细
/*
const int N = 1e6 + 10;
char s[N], t[N];

int main()
{
	int T;
	cin >> T;

	while (T--)
	{
		string s1;
		string s2;
		cin >> s2 >> s1;
		int n = s1.size(); //获取字符串的长度

		int res = 0;
		for (int i = 0; i < n; ++i)
		{
			if (s1[i] != s2[i]) //字符串不想等，需要改变
			{
				//无法进行改变(题意)
				if (!i || i == n - 1 || s1[i] == s1[i - 1] || s1[i] == s1[i + 1])
				{
					res = -1;
					break;
				}
				res++;
				s1[i] = s2[i];
			}
		}
		printf("%d\n", res);
	}

	return 0;
}
*/


//劲舞团
/*
struct dance{
	char a,b;
	ll c;
}play[2010];

bool check(ll a, ll b){
	string  temp= to_string(a);
	string  temp1= to_string(b);
	int itmp1 =	0;
	int itmp2 = 0;
	for(int i = temp.size()-5; i <= temp.size()-1; ++i){
		itmp1 = itmp1 *10 + (temp[i] - '0') ;
		itmp2 = itmp2 *10 + (temp1[i] - '0');
	}
	if(abs(itmp1 - itmp2) > 1000){
		return false;
	}
	return true;
}



int main(){
	ll ans =1;
	ll temp=1;
	for(int i = 1; i <=2000 ;++i){
		string s;
		getline(cin, s);
		sscanf(s.c_str(), "%c %c %lld",&play[i].a,&play[i].b, &play[i].c);
	}
	cout<<"------------"<<endl;
	for(int i = 1; i <=2000 ;++i){
		printf("%c %c %lld\n",play[i].a,play[i].b, play[i].c);
	}
	for(int i = 1; i <=2000 ;++i){
		if(i==2000)
			break;
		if((play[i].a == play[i].b) && (play[i+1].a == play[i+1].b) &&check(play[i].c, play[i+1].c)){
			temp++;
		}
		else{
			temp =1;
		}
		ans = max(ans, temp);
	}
	cout<<"ans: "<<ans<<endl;
	return 0;
}
*/


//1.
/*
typedef  long long ll;

struct myDate{
	int year,month,day;
	int hour,minu,s;
}a[530];

bool cmp(myDate a, myDate b){
	if(a.year != b.year)
		return a.year<b.year;

	if(a.month != b.month)
		return a.month<b.month;

	if(a.day != b.day)
		return a.day<b.day;

	if(a.hour != b.hour)
		return a.hour<b.hour;
	if(a.minu != b.minu)
		return a.minu<b.minu;
	if(a.s != b.s)
		return a.s<b.s;
}
ll caucal(int x){
	return a[x].day*24*60*60 +  a[x].hour*60*60 +a[x].minu*60+a[x].s;
}


void solve(){
	ll ans=0;
	for(int i = 1; i <= 520; ++i){
		string s;
		getline(cin, s);
		sscanf(s.c_str(),"%d-%d-%d %d:%d:%d", &a[i].year,&a[i].month, &a[i].day,
				 &a[i].hour,  &a[i].minu,  &a[i].s);
	}
	cout<<"----------"<<'\n';
	sort(a+1, a+520+1, cmp);
	for(int i = 1; i <= 520; ++i){
		printf("%d-%d-%d %d:%d:%d\n", a[i].year,a[i].month, a[i].day,
				 a[i].hour,  a[i].minu,  a[i].s);
	}
	for(int i = 1; i <= 520; i+=2){
		ans = ans + caucal(i+1) - caucal(i);
	}
	cout<<"ans: "<<ans<<'\n';

	return;
}



int main(){

	solve();
	return 0;

}
*/


//2.
/*
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N = 1e5+10;
ll ans;
int arr[5][5];
 ll ret;
int dfs(int a, int b){
//	if(a > 4 || b >4)
//		return;
	ans++;
	if(a==0 && (b==0 || b==2 || b==4)){
		return arr[a][b] = 1;
	}
	if(a==0 && (b==1 || b==3)){
		return arr[a][b] = 0;
	}


	ret =  ( (dfs(a-1, b) | dfs(a-1,b+1)) == 1) + ( (dfs(a-1, b) | dfs(a-1,b+1)) == 1)
		+ ( (dfs(a-1, b) | dfs(a-1,b+1)) == 1) ;

	return ans;
}


void solve(){

	int ret = dfs(2,3);
	cout<<ret;
	return;
}

int main(){

//	arr[0][0] = arr[0][2] = arr[0][4] = 1;
//	arr[0][1] = arr[0][3] = 0;

	solve();
	return 0;
}
*/

//7.
/*
int n,X,Y;

int _X[N],_Y[N],L[N];
void solve(){
	for(int i = 1; i<= n; ++i){
		for(int j = i + 1; j<= n; ++j){
			if(_Y[i] > _Y[j] && _X[i] <= _X[j] && L[i] >= L[j])
				ans--;
			if(_Y[j] > _Y[i] && _X[j] <= _X[i] && L[j] >= L[i])
				ans--;

		}
	}
	cout<<ans;
	return ;
}


int main()
{
  cin >> n >> X >> Y;
  ans =n;
  for(int i = 1; i<= n; ++i){
	cin >> _X[i] >> _Y[i]>> L[i];
	L[i] = L[i] +_X[i];
  }
  solve();

  return 0;
}

*/



// 6.
/*
int n,m;

bool check1(ll x){
	int cnt = 0;//0奇数位 ,1偶数wei
	while(x > 0){
		int temp = x%10;
		if(cnt==0 && (temp%2 == 0))
			return false;
		if(cnt==1 && (temp%2 != 0))
			return false;
		cnt ^= 1;
		x/=10;
	}
	return true;
}
bool check2(int x){
	string s = to_string(x);
	ll temp1 =0;
	for(int i = 0; i < s.size(); ++i){
		temp1 += (s[i] - '0');
	}
	if(temp1 > m)
		return false;
	else
		return true;
}



void solve(ll begin, ll end){
	for(ll i = begin; i < end; ++i){
		if(check1(i) && check2(i))
			ans = (ans +1) % 998244353;
	}
	cout<<ans;
	return;
}


int main()
{
  cin>>n>>m;
  ll begin = (ll)pow(10,n-1);

  ll end = (ll)pow(10,n);

  solve(begin,end);
  return 0;
}
*/


//5.
/*
int n;
int a[N];

int gcd(int a, int b){
	return b?gcd(b,a%b):a;
}


bool check(int a, int b){
	if(gcd(a,b) > 1)
		return true;
	return false;

}


void solve(){
	for(int i = 1; i<=n; ++i){
		for(int j = i + 1; j<=n; ++j){
			if(check(a[i],a[j])){
				cout<<i<<" "<<j<<'\n';
				return ;
			}
		}
	}
	return ;
}



int main()
{
	cin>>n;
	for(int i = 1; i<=n; ++i){
		cin>>a[i];
	}
	solve();
	return 0;
}
*/



//4.
/*
int n;
int a[N];
ll temp;
ll yinshu[N];
ll pos =0;
ll jiecheng(int x){
	ll tmp =1;
	for(int i =x; i>0; --i){
		tmp =tmp*i;
	}
	return tmp;
}

void yinshu(int x){

	for(int i =1; i*i <x; ++i){
		if( x % i == 0 ){
			yingshu[pos++] = i;
		}
	}

}

bool check(int x){

	return false;
}

void solve(){
	ll jisuan =0;
	for(int i = 1; i<=n; ++i){
		jisuan = jisuan + jiecheng(a[i]);
	}
	yinshu(jisuan);
	for(int i = 1; i<=n; ++i){
		if(jiecheng(i) );
	}

}



int main(){
	cin>>n;
	for(int i = 1; i<=n; ++i){
		cin>>a[i];
	}
	solve();
	return 0;
}
*/


